<template>
  <!-- 轮播海报 -->
  <div class="bannerBar">
    <!-- 瀑布流展示海报 -->
    <div v-if="type == 'waterfall'" class="preView" :id="widgetData.siteId">
      <!-- 热力图 -->
      <template v-for="(ele, idx) in mapData">
        <div v-if="ele.sitePageId == widgetData.siteId" :key="idx + 'a'" class="mark"
          :style="{ background: `#${ele.color}`, opacity: 0.9 }">
          <div>
            <div class="name">PV：{{ ele.exposurePv }}</div>
            <div class="name">UV：{{ ele.exposureUv }}</div>
          </div>
          <div class="level">Lv.{{ ele.level }}</div>
        </div>
      </template>
      <!-- 组件 -->
      <div v-if="widgetData.defaultImg != '' && widgetData.siteId == bannerSiteCode" style="width:100%;height:100%">
        <img :src="widgetData.defaultImg">
      </div>
      <div v-else style="width:100%;height:100%">
        <img v-if="widgetData.value[0].url != ''" :src="widgetData.value[0].url">
        <div v-else class="image-null"><i class="el-icon-picture"></i></div>
      </div>
      <!-- 列表 -->
      <div class="list">
        <div class="overflow">
          <div class="imgList" :class="{ Border: bannerSiteCode == item.siteId }" v-for="(item, idx) in widgetData.value"
            :key="idx" @click="preView($event, item, idx, widgetData)">
            <img v-if="item.url && item.url != ''" :src="item.url"
              :style="{ width: bannerSiteCode == item.siteId ? '44px' : '48px', height: bannerSiteCode == item.siteId ? '44px' : '48px' }">
            <div v-else class="image-null"><i class="el-icon-picture"></i></div>
          </div>
        </div>
      </div>
    </div>

    <!-- 模板展示海报 -->
    <div v-else class="preView">
      <div v-if="widgetData.defaultImg != ''" style="width:100%;height:100%">
        <img :src="widgetData.defaultImg">
      </div>
      <div v-else style="width:100%;height:100%">
        <div v-if="widgetData.value.length > 0" style="width:100%;height:100%">
          <img v-if="widgetData.value[0].url != ''" :src="widgetData.value[0].url">
          <div v-else class="image-null"><i class="el-icon-picture"></i></div>
        </div>
        <div v-else style="width:100%;height:100%">
          <div class="image-null"><i class="el-icon-picture"></i></div>
        </div>
      </div>
      <!-- 列表 -->
      <div class="list">
        <div class="overflow">
          <div class="imgList" :class="{ Border: bannerIndex == item.index }" v-for="(item, idx) in widgetData.value"
            :key="idx" @click="preView($event, item, idx, widgetData)">
            <img v-if="item.url && item.url != ''" :src="item.url"
              :style="{ width: bannerIndex == item.index ? '44px' : '48px', height: bannerIndex == item.index ? '44px' : '48px' }">
            <div v-else class="image-null"><i class="el-icon-picture"></i></div>
            <i v-if="!ispreview" class="el-icon-error" @click.stop="deleteItem(idx)"></i>
          </div>
          <div class="add" @click="addImg" v-if="!ispreview">
            <div class="image-null"><i class="el-icon-plus" style="font-size: 30px;"></i></div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "bannerBar",
  props: {
    type: {
      type: String,
      default: 'widget'
    },
    widgetData: {
      type: Object,
      required: true
    },
    bannerIndex: {//模板参数
      type: Number,
      default: 0
    },
    bannerSiteCode: {//瀑布流参数
      type: String,
      default: ''
    },
    // 热力图
    mapData: {
      type: Array,
      default: () => []
    },
    ispreview: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {}
  },
  methods: {
    // 添加
    addImg() {
      this.$emit('addImg');
    },
    // 预览
    preView(e, item, index, data) {
      this.$emit('preView', e, item, index, data);
    },
    // 删除
    deleteItem(index) {
      this.$emit('deleteItem', index);
    }
  },
}
</script>

<style lang="scss" scoped>
.bannerBar {
  width: 100%;
  height: 100%;

  .preView {
    width: 100%;
    height: 100%;
    position: relative;

    // 热力图
    .mark {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      padding: 10px 15px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      z-index: 9;

      .name {
        color: #ffffff;
      }

      .level {
        color: #ffffff;
        text-align: right;
      }
    }
  }

  img {
    width: 100%;
    height: 100%;
  }

  .image-null {
    background: #ffffff;
    width: 100%;
    height: 100%;
    font-size: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #c1c1c1;
  }

  .list {
    width: 100%;
    height: 60px;
    overflow-y: auto;
    background-color: rgba(29, 25, 25, 0.103);
    position: absolute;
    bottom: 0px;

    .overflow {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: flex-start;
      flex-wrap: wrap;
    }

    .imgList {
      width: 48px;
      height: 48px;
      // border: 1px dashed #c1c1c1;
      margin: 5px 0px 5px 5px;
      position: relative;

      &:hover {
        .el-icon-error {
          display: block;
        }
      }

      .el-icon-error {
        position: absolute;
        right: -10px;
        top: -6px;
        color: red;
        font-size: 25px;
        cursor: pointer;
        display: none;
        z-index: 9999;
      }
    }

    .add {
      width: 48px;
      height: 48px;
      margin: 5px;
      background-color: rgba(0, 0, 0, 0.1);
      display: flex;
      align-items: center;
      justify-content: center;
      color: #ffffff;
      border: 1px dashed blue;
    }

    // 选中样式
    .Border {
      border: 2px dashed rgb(0, 255, 0) !important;
    }
  }

  // 锚点定位
  .anchor {
    box-shadow: 1px 1px 10px 10px red;
  }
}
</style>

<style lang="scss" scoped>
/*定义滚动条高宽及背景 高宽分别对应横竖滚动条的尺寸*/
::-webkit-scrollbar {
  // width: 16px;  /*滚动条宽度*/
  // height: 16px;  /*滚动条高度*/
}

/*定义滚动条轨道 内阴影+圆角*/
::-webkit-scrollbar-track {
  // -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
  // border-radius: 10px;  /*滚动条的背景区域的圆角*/
  // background-color: red;/*滚动条的背景颜色*/
}

/*定义滑块 内阴影+圆角*/
::-webkit-scrollbar-thumb {
  // border-radius: 10px;  /*滚动条的圆角*/
  // -webkit-box-shadow: inset 0 0 6px rgba(0,0,0,.3);
  background-color: red;
  /*滚动条的背景颜色*/
}
</style>